﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace SharepointLogReader
{
    public class SearchTextsLog
    {
        public static void AddSearchTextToLog(string searchText)
        {
            List<string> allSearchTexts = GetSearchTextsLog();

            if (allSearchTexts.Contains(searchText))
            {
                allSearchTexts.Remove(searchText);
            }

            allSearchTexts.Insert(0, searchText);
            allSearchTexts = allSearchTexts.Take(20).ToList();

            Serializer.SaveObject(allSearchTexts, Consts.LOG_TEXT_SEARCH_FILE);
        }
        public static List<string> GetSearchTextsLog()
        {
            List<string> readSearchTexts = new List<string>();
            if (File.Exists(Consts.LOG_TEXT_SEARCH_FILE))
            {
                readSearchTexts = Serializer.ReadObject(Consts.LOG_TEXT_SEARCH_FILE, typeof(List<string>)) as List<string>;
            }
            return readSearchTexts;
        }
    }
}
